package Question13;

import java.util.Scanner;

/**
 * Created by stevenfen on 2017/3/12.
 */
public class Question13 {
    /**
     *
     * @param gezi 目前的格子状态
     * @param type 放的火柴棍的方向
     * @return 是否能放
     */
    private static Boolean isSet(String[][] gezi,int x, int y,String type){
        Boolean ok = Boolean.FALSE;
        if(type.equals("-")){
            for(int start = y-1;start>=0;start--){
                if(!gezi[x][start].equals("")){
                    if(gezi[x][start].equals("1")){
                        ok = Boolean.TRUE;
                    }
                    break;
                }
            }

            if(!ok) {
                for (int start = y + 1; start < 4; start++) {
                    if (!gezi[x][start].equals("")) {
                        if (gezi[x][start].equals("1")) {
                            ok = Boolean.TRUE;
                        }
                        break;
                    }
                }
            }
        }else{
            for(int start = x-1;start>=0;start--){
                if(!gezi[x][start].equals("")){
                    if(gezi[x][start].equals("-")){
                        ok = Boolean.TRUE;
                    }
                    break;
                }
            }

            if(!ok) {
                for (int start = x + 1; start < 3; start++) {
                    if (!gezi[x][start].equals("")) {
                        if (gezi[x][start].equals("-")) {
                            ok = Boolean.TRUE;
                        }
                        break;
                    }
                }
            }
        }
        return ok;
    }

    /**
     *
     * @param inputs 键盘输入的矩阵
     * @return 转换后的字符串矩阵
     */
    private static String[][] createJuZhen(String[] inputs){
        String[][] answer = new String[3][4];

        for(int i = 0; i< 3;i++){
            answer[i][0] = inputs[i].substring(0,1);
            answer[i][1] = inputs[i].substring(1,2);
            answer[i][2] = inputs[i].substring(2,3);
            answer[i][3] = inputs[i].substring(3,4);
        }

        return answer;
    }

    /**
     *
     * @param inputs 字符串矩阵
     * @return 该局势下对手有多少种选择
     */
    private static Integer count(String[][] inputs){
        int count = 0;

        for(int i=0;i<3;i++){
            for(int j = 0;j < 4;j++){
                if(inputs[i][j].equals("0")){
                    if(Question13.isSet(inputs,i,j,"-")){
                        count++;
                    }

                    if(Question13.isSet(inputs,i,j,"1")){
                        count++;
                    }

                }
            }
        }

        return count;
    }

    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        String[] origin  = new String[3];
        String[][] deal;
        int n = Integer.parseInt(scanner.nextLine());

        while(n-->0){

           for(int i = 0;i<3;i++){
               origin[i]= scanner.nextLine();
           }

           deal = Question13.createJuZhen(origin);

            int min = Integer.MAX_VALUE;
            int maxi = 0;
            int maxj = 0;
            String type = "";

            for(int i=0;i<3;i++){
                for(int j=0;j<4;j++){
                    if(deal[i][j].equals("0")){
                        if(Question13.isSet(deal,i,j,"-")){
                            deal[i][j] = "-";
                            int count  = Question13.count(deal);
                            if( count < min){
                                min = count;
                                maxi = i;
                                maxj = j;;
                                type = "-";
                            }
                        }

                        if(Question13.isSet(deal,i,j,"1")){
                            deal[i][j] = "1";
                            int count  = Question13.count(deal);
                            if( count < min){
                                min = count;
                                maxi = i;
                                maxj = j;
                                type = "1";
                            }
                        }

                        deal[i][j] = "0";
                    }
                }
            }

            System.out.println(maxi + ""+maxj + "" + type);
        }
    }
}
